package kioschool.basic.model
{
	import mx.core.mx_internal;
	import prim.model.PrimVertex;

	/**
	 * Список нумерованных вершин
	 * @author Akimushkin Vasiliy
	 */ 
	public class QueryOfVertex
	{
		private var _array:Array = new Array();
		
		public function QueryOfVertex(arr:Array)
		{
			for (var i:int; i < arr.length; i++ ) {
				var vertex:Vertex = arr[i];
				var vertexInQuery:VertexInQuery = new VertexInQuery();
				vertexInQuery.vertex=vertex;
				vertexInQuery.number=-1;
				_array.push(vertexInQuery);
			}
			
		}
		
		public function get array():Array
		{
			return _array;
		}

		public function getLast():PrimVertex {
			var num:int = -1;
			var v:Vertex = null;
			var vv:VertexInQuery = null;
			for (var i:int; i < _array.length; i++ ) {
				var vertex:VertexInQuery = _array[i];
				if (vertex.number > num) {
					num = vertex.number;
					v = Vertex(vertex.vertex);
					vv = vertex;
				}
			}
			return v;
		}
		
		public function popLast():PrimVertex {
			var num:int = -1;
			var v:Vertex = null;
			var vv:VertexInQuery = null;
			for (var i:int; i < _array.length; i++ ) {
				var vertex:VertexInQuery = _array[i];
				if (vertex.number > num) {
					num = vertex.number;
					v = Vertex(vertex.vertex);
					vv = vertex;
				}
			}
			if(vv!=null)
				vv.number = -1;
			return v;
		}

	}
}